import  random

# 系统生成一个随机数
num = random.randint(1,100)
count = 0

money = 5000
x=True
while x:
    count += 1
    # 用户猜随机数
    a = input("请输入猜的数字：")
    a = int(a)
    if money>=500:
        if a > num:
            money -= 500
            print(f"大了！您的余额为{money}")
        elif a < num:
            money -= 500
            print(f"小了！您的余额为{money}")
        else:
            money+=3000
            print("恭喜，猜中！幸运数字为：",num,"，本轮猜了",count,"次!获得奖励3000金币，您的余额为",money)
            while True:
                b = int(input("是否进行下一轮游戏？继续：请输入1，结束:请输入0   "))
                if b==0:
                    x=False
                    print("游戏结束！")
                    break
                elif b==1:
                    break
                else:
                    print("输入的数字有误，请重新输入")
                    continue

    else:
        print("余额不足，请充值！")
        break










